﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Solidorbrazedturningtoolno7groovingandcutoffdesign1
    {
        public static void _Solidorbrazedturningtoolno7groovingandcutoffdesign1(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数

            double oal = 36.59;
            double dconms = 6.88;
            double lpr = 19.34;
            double cdx = 8.99;
            double cw = 2.66;
            double wf = 3.32;
            double kapr = 90;
            double ral = 2;
            double lh = 15.03;
            double s = 1.32;
            double hea1 = 45;
            double hea2 = 45;


            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal + 4, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 2, v1.Y);
            Vector2 v4 = new Vector2(v3.X + oal, v3.Y);
            Vector2 v6 = new Vector2(v3.X, v3.Y - dconms / 2);
            Vector2 v5 = new Vector2(v4.X - dconms / 2 * Math.Tan(27 * pi / 180), v6.Y);
            Vector2 v7 = new Vector2(v4.X - s * Math.Tan(27 * pi / 180), v4.Y - s);
            Vector2 v8 = new Vector2(v4.X - cdx / 1.4384, v7.Y);
            Vector2 v9 = new Vector2(v8.X, v4.Y - (v4.X - v8.X) * Math.Tan(4 * pi / 180));
            Vector2 v10 = new Vector2(v4.X - cdx, v4.Y - cdx * Math.Tan(4 * pi / 180));
            Vector2 v11 = new Vector2(v4.X - lh / 1.0155, v3.Y + dconms / 2);
            Vector2 v12 = new Vector2(v4.X - lh, v11.Y);
            Vector2 v13 = new Vector2(v12.X, v6.Y);
            Vector2 v14 = new Vector2(v3.X, v12.Y);
            Vector2 v38 = new Vector2(v4.X - lpr, v4.Y);
            Vector2 v39 = new Vector2(v4.X + dconms, v4.Y);

            Vector2 v15 = new Vector2(v1.X, v1.Y - oal / 1.446);
            Vector2 v16 = new Vector2(v2.X, v15.Y);
            Vector2 v17 = new Vector2(v15.X + 2, v15.Y);
            Vector2 v18 = new Vector2(v17.X, v17.Y + dconms / 2);
            Vector2 v19 = new Vector2(v18.X, v18.Y - dconms);
            Vector2 v20 = new Vector2(v17.X + oal, v17.Y - wf);
            Vector2 v21 = new Vector2(v20.X - cdx, v20.Y + cdx * Math.Tan(ral * pi / 180));
            Vector2 v22 = new Vector2(v20.X, v20.Y + cw);
            Vector2 v23 = new Vector2(v22.X - cdx, v22.Y - cdx * Math.Tan(ral * pi / 180));
            Vector2 v24 = new Vector2(v22.X - cdx / 1.07, v22.Y - cdx / 1.07 * Math.Tan(ral * pi / 180));
            Vector2 v25 = new Vector2(v24.X - (v18.Y - v24.Y) / Math.Tan(hea1 * pi / 180), v18.Y);
            Vector2 v26 = new Vector2(v24.X, v20.Y + (v22.Y - v24.Y));
            Vector2 v27 = new Vector2(v26.X - (v26.Y - v19.Y) / Math.Tan(hea2 * pi / 180), v19.Y);
            Vector2 v28 = new Vector2(v20.X - lh, v18.Y);
            Vector2 v29 = new Vector2(v28.X, v19.Y);
            Vector2 v30 = new Vector2(v25.X - (lh - cdx) / 3.393, v25.Y - dconms / 3.031);
            Vector2 v31 = new Vector2(v30.X - (lh - cdx) / 22.37, v15.Y);
            Vector2 v32 = new Vector2(v31.X + (lh - cdx) / 43.143, v31.Y - dconms / 6.68);
            Vector2 v33 = new Vector2(v32.X + (lh - cdx) / 3.066, v19.Y);
            Vector2 v34 = new Vector2(v24.X + cdx / 21.927, v24.Y - cw / 8.3125);
            Vector2 v35 = fun.Polar(v34, ral * pi / 180, cdx / 1.21);
            Vector2 v36 = new Vector2(v35.X, v20.Y + (v22.Y - v35.Y));
            Vector2 v37 = new Vector2(v34.X, v26.Y + (v24.Y - v34.Y));
            Vector2 v40 = new Vector2(v38.X, v15.Y);



            //作图
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v7));
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v14));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v13));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v11));
            line2.Vertexes.Add(new LwPolylineVertex(v10));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes[10].Bulge = Math.Tan(76 * pi / 180 / 4);
            fun.PolyFill(dxf, line2, 0.2, contour);

            Line line3 = new Line(v15, v16);
            line3.Layer = centre;
            line3.Linetype = Linetype.DashDot;
            line3.LinetypeScale = 3;
            dxf.AddEntity(line3);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v24));
            line4.Vertexes.Add(new LwPolylineVertex(v23));
            line4.Vertexes.Add(new LwPolylineVertex(v21));
            line4.Vertexes.Add(new LwPolylineVertex(v20));
            line4.Vertexes.Add(new LwPolylineVertex(v22));
            line4.Vertexes.Add(new LwPolylineVertex(v24));
            line4.Vertexes.Add(new LwPolylineVertex(v25));
            line4.Vertexes.Add(new LwPolylineVertex(v18));
            line4.Vertexes.Add(new LwPolylineVertex(v19));
            line4.Vertexes.Add(new LwPolylineVertex(v27));
            line4.Vertexes.Add(new LwPolylineVertex(v26));
            fun.PolyFill(dxf, line4, 0.2, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v28));
            line5.Vertexes.Add(new LwPolylineVertex(v29));
            line5.Vertexes.Add(new LwPolylineVertex(v33));
            line5.Vertexes.Add(new LwPolylineVertex(v32));
            line5.Vertexes[2].Bulge = Math.Tan(-37 * pi / 180 / 4);
            fun.PolyFill(dxf, line5, 0.2, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v25));
            line6.Vertexes.Add(new LwPolylineVertex(v30));
            line6.Vertexes[0].Bulge = Math.Tan(18 * pi / 180 / 4);
            fun.PolyFill(dxf, line6, 0.2, contour);

            Arc c1 = fun.DrawArc3(v30, v31, v32);
            fun.drawBArc(dxf, c1, 0.2, contour);

            Line line7 = new Line(v24, v34);
            line7.Layer = refin;
            line7.Linetype = Linetype.Dashed;
            line7.LinetypeScale = 5;
            dxf.AddEntity(line7);

            Line line8 = new Line(v35, v34);
            line8.Layer = refin;
            line8.Linetype = Linetype.Dashed;
            line8.LinetypeScale = 5;
            dxf.AddEntity(line8);

            Line line9 = new Line(v35, v36);
            line9.Layer = refin;
            line9.Linetype = Linetype.Dashed;
            line9.LinetypeScale = 5;
            dxf.AddEntity(line9);

            Line line10 = new Line(v36, v37);
            line10.Layer = refin;
            line10.Linetype = Linetype.Dashed;
            line10.LinetypeScale = 5;
            dxf.AddEntity(line10);

            Line line11 = new Line(v26, v37);
            line11.Layer = refin;
            line11.Linetype = Linetype.Dashed;
            line11.LinetypeScale = 5;
            dxf.AddEntity(line11);

            fun.drawcircle(dxf, v4, 1, 0.02, dimensioning);

            fun.drawcircle(dxf, v20, 1, 0.02, dimensioning);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v4));
            line12.Vertexes.Add(new LwPolylineVertex(v39));
            fun.PolyFill(dxf, line12, 0.02, dimensioning);


            //坐标系
            fun.Axis(dxf, v3, 90, 180, "Y", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v38, 90, 180, "Y", "Z", "MCS", 0.5, 2, 0);

            fun.Axis(dxf, v17, -90, 180, "X", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v40, -90, 180, "X", "Z", "MCS", 0.5, 2, 0);




            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;



            fun.dimrot1(dxf, v18, v19, 90, dconms, 1, height, arrowsize, exline, "DCONMS", "", "");

            fun.dimrot1(dxf, v21, v20, 180, dconms, 1, height, arrowsize, exline, "CDX", "", "");

            fun.dimrot1(dxf, v29, v20, 180, dconms * 1.5, 1, height, arrowsize, exline, "LH", "", "");

            fun.dimrot1(dxf, v19, v20, 180, dconms * 3, 1, height, arrowsize, exline, "OAL,LF", "", "");

            fun.dimrot1(dxf, v40, v20, 180, dconms * 2.5, 1, height, arrowsize, exline, "LPR,LTA", "", "");

            fun.dimrot1(dxf, v22, v20, -90, dconms, 1, height, arrowsize, exline, "CW", "", "");

            fun.dimrot1(dxf, v16, v20, -90, dconms * 1.5, 1, height, arrowsize, exline, "wf,WTA", "", "");

            fun.jdbz2(dxf, new Line(v20, fun.Polar(v20, 0 * pi / 180, 0.1)), new Line(v20, fun.Polar(v20, kapr * pi / 180, 0.1)), dconms * 2.5, height, arrowsize, exline, "KAPR", "", "");

            fun.jdbz2(dxf, new Line(v22, fun.Polar(v22, 180 * pi / 180, 0.1)), new Line(v22, fun.Polar(v22, (ral - 180) * pi / 180, 0.1)), cdx * 0.8, height, arrowsize, exline, "RAL", "", "");

            fun.jdbz2(dxf, new Line(v20, fun.Polar(v20, (-ral + 180) * pi / 180, 0.1)), new Line(v20, fun.Polar(v20, 180 * pi / 180, 0.1)), cdx * 0.8, height, arrowsize, exline, "RAR", "", "");

            fun.jdbz2(dxf, new Line(v25, fun.Polar(v25, (-hea1 + 180) * pi / 180, 0.1)), new Line(v25, fun.Polar(v25, 180 * pi / 180, 0.1)), cdx / 2, height, arrowsize, exline, "HEA_1", "", "");

            fun.jdbz2(dxf, new Line(v27, fun.Polar(v27, 180 * pi / 180, 0.1)), new Line(v27, fun.Polar(v27, (-180+hea2) * pi / 180, 0.1)), cdx / 2, height, arrowsize, exline, "HEA_2", "", "");

            fun.jt(dxf, new Vector2(v20.X + oal / 4.414, v20.Y - dconms / 0.503), 180, 5, height, "FDP");

            fun.jt(dxf, new Vector2(v18.X + oal / 6, v18.Y), 115, 5, height, "CCMS");

            fun.jt(dxf, new Vector2(v39.X - 0.3, v39.Y), 90, 5, height, "HTA,HF");

            fun.text1(dxf, new Vector2(v4.X, v4.Y + dconms / 3.843), 90, "CRP");

            fun.text1(dxf, new Vector2(v20.X + cdx / 11.675, v20.Y -dconms /1.553), 90, "CRP");



            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}